
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/message/history/history.js'
], function (require, exports) {
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('CHANNEL_TYPE');
    yufp.lookup.reg('MESSAGE_STATE');
    yufp.custom.vue({
      el: '#messageSendInfo',
      data: function () {
        return {
          formdata: {},
          height: yufp.custom.viewSize().height,
          urls: {
            dataUrl: backend.messageService + '/api/template/queryMessageResult/',
            sendAgainUrl: backend.messageService + '/api/template/sendAgain/'
          },
          tableColumns: [
            { label: this.$t('history.zj'), prop: 'pkNo', resizable: true, hidden: true },
            { label: this.$t('history.yhm'), prop: 'userNo', resizable: true },
            { label: this.$t('history.fsjg'), prop: 'state', resizable: true, type: 'select', dataCode: 'MESSAGE_STATE' },
            { label: this.$t('history.qdlx'), prop: 'channelType', resizable: true, type: 'select', dataCode: 'CHANNEL_TYPE' },
            { label: this.$t('history.fssj'), prop: 'sendTime', resizable: true }
          ],
          resultOptions: [{ key: 'S', value: this.$t('history.cg') }, { key: 'F', value: this.$t('history.sb') }],
          check: true
        };
      },
      methods: {
        sendAgain: function () {
          if (this.$refs.messageTable.selections.length > 0) {
            var pkNos = '';
            if (this.$refs.messageTable.selections.length >= 1) {
              for (var i = 0; i < this.$refs.messageTable.selections.length; i++) {
                pkNos = pkNos + this.$refs.messageTable.selections[i].pkNo + ',';
                if (this.$refs.messageTable.selections[i].state == 'S') {
                  this.$message({ message: this.$t('history.fscgdxxbkzf'), type: 'warning' });
                  return;
                }
              }
            }
            var me = this;
            var comData = { pkNos: pkNos };
            this.$confirm(this.$t('history.nqdycxfsxxm'), this.$t('history.ts'), {
              confirmButtonText: this.$t('history.qd'),
              cancelButtonText: this.$t('history.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                data: comData,
                url: me.urls.sendAgainUrl,
                callback: function (code, message, response) {
                  if (response.data == 0) {
                    me.$message({ message: me.$t('history.fscg'), type: 'success' });
                    me.$refs.messageTable.remoteData();
                  } else {
                    me.$message({ message: me.$t('history.fssb'), type: 'error' });
                  }
                }
              });
            });
          } else {
            this.$message({ message: this.$t('history.qxxzsj'), type: 'warning' });
            return false;
          }
        }
      }
    });
  };

  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
